package com.hengxinguotong.zhihuichengjian.bean;

import com.hengxinguotong.zhihuichengjian.treeview.Node;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 安全检查项目
 * Created by Administrator on 2017/10/18.
 */

public class SafetyBean extends Node<String> implements Serializable, Cloneable{
    private String parentId;//父节点ID
    private String id;//检查项ID
    private String name;//检查项名称
    private boolean isSelected = false;//是否被选中
    private List<SafetyBean> data = new ArrayList<>();

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public boolean isSelected() {
        return isSelected;
    }

    public void setSelected(boolean selected) {
        isSelected = selected;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<SafetyBean> getData() {
        return data;
    }

    public void setData(List<SafetyBean> data) {
        this.data = data;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof SafetyBean) {
            SafetyBean t = (SafetyBean) obj;
            if(t.parentId != null){
                return this.name.equals(t.name) && this.id.equals(t.id) && this.parentId.equals(t.getParentId());
            }else{
                return this.name.equals(t.name) && this.id.equals(t.id);
            }
        }
        return super.equals(obj);
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        SafetyBean obj = (SafetyBean)super.clone();
        List<SafetyBean> safetyList = new ArrayList<SafetyBean>();
        List<SafetyBean> list = getData();
        if (list != null) {
            for (SafetyBean bean : list) {
                SafetyBean b = (SafetyBean)bean.clone();
                safetyList.add(b);
            }
            obj.setData(safetyList);
        }
        return obj;
    }

    @Override
    public String get_id() {
        return getId();
    }

    @Override
    public String get_parentId() {
        return getParentId();
    }

    @Override
    public String get_label() {
        return getName();
    }

    @Override
    public String get_startTime() {
        return null;
    }

    @Override
    public String get_endTime() {
        return null;
    }

    @Override
    public String get_status() {
        return null;
    }

    @Override
    public float get_percent() {
        return 0;
    }

    @Override
    public void set_percent(float percent) {

    }

    @Override
    public int get_planDays() {
        return 0;
    }

    @Override
    public int get_realDays() {
        return 0;
    }

    @Override
    public boolean parent(Node dest) {
        if (id.equals((String)dest.get_parentId())){
            return true;
        }
        return false;
    }

    @Override
    public boolean child(Node dest) {
        if (get_parentId().equals((String) dest.get_id())){
            return true;
        }
        return false;
    }
}
